home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5107 < prev    next >
Mailbox/MIME Entity  |  1996-08-05  |  4.4 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: Mailbox/MIME Entity (archive/mbox).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert Newsgroup Content (archive/news) magic Supported
100% dexvert Mailbox/MIME Entity (archive/mbox) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file news text default
99% file C source, ASCII text default
100% checkBytes Printable ASCII default
100% dexmagic PrintFox/Pagefox WEAK default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/950 MIME Email (1.0) default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime message/news default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 50 61 74 68 3a 20 69 78 | 2e 6e 65 74 63 6f 6d 2e |Path: ix|.netcom.|
|00000010| 63 6f 6d 21 6e 65 74 6e | 65 77 73 0a 46 72 6f 6d |com!netn|ews.From|
|00000020| 3a 20 4e 6f 72 6d 61 6e | 20 42 75 6c 6c 65 6e 20 |: Norman| Bullen |
|00000030| 3c 6e 62 75 6c 6c 65 6e | 40 69 78 2e 6e 65 74 63 |<nbullen|@ix.netc|
|00000040| 6f 6d 2e 63 6f 6d 3e 0a | 4e 65 77 73 67 72 6f 75 |om.com>.|Newsgrou|
|00000050| 70 73 3a 20 63 6f 6d 70 | 2e 6c 61 6e 67 2e 63 0a |ps: comp|.lang.c.|
|00000060| 53 75 62 6a 65 63 74 3a | 20 52 65 3a 20 43 6f 6e |Subject:| Re: Con|
|00000070| 76 65 72 73 69 6f 6e 20 | 6f 66 20 6d 6d 2f 64 64 |version |of mm/dd|
|00000080| 2f 79 79 20 66 6f 72 6d | 61 74 20 74 6f 20 6a 75 |/yy form|at to ju|
|00000090| 6c 69 61 6e 20 64 61 74 | 65 20 66 6f 72 6d 61 74 |lian dat|e format|
|000000a0| 0a 44 61 74 65 3a 20 54 | 68 75 2c 20 30 38 20 46 |.Date: T|hu, 08 F|
|000000b0| 65 62 20 31 39 39 36 20 | 30 37 3a 30 36 3a 34 32 |eb 1996 |07:06:42|
|000000c0| 20 2d 30 38 30 30 0a 4f | 72 67 61 6e 69 7a 61 74 | -0800.O|rganizat|
|000000d0| 69 6f 6e 3a 20 42 6c 61 | 63 6b 20 43 61 74 20 41 |ion: Bla|ck Cat A|
|000000e0| 73 73 6f 63 69 61 74 65 | 73 0a 4d 65 73 73 61 67 |ssociate|s.Messag|
|000000f0| 65 2d 49 44 3a 20 3c 33 | 31 31 41 31 31 38 32 2e |e-ID: <3|11A1182.|
|00000100| 35 40 69 78 2e 6e 65 74 | 63 6f 6d 2e 63 6f 6d 3e |5@ix.net|com.com>|
|00000110| 0a 52 65 66 65 72 65 6e | 63 65 73 3a 20 3c 34 65 |.Referen|ces: <4e|
|00000120| 70 68 30 72 24 38 6a 71 | 40 6e 65 77 73 33 2e 64 |ph0r$8jq|@news3.d|
|00000130| 69 67 65 78 2e 6e 65 74 | 3e 0a 4e 4e 54 50 2d 50 |igex.net|>.NNTP-P|
|00000140| 6f 73 74 69 6e 67 2d 48 | 6f 73 74 3a 20 70 6c 65 |osting-H|ost: ple|
|00000150| 2d 63 61 31 30 2d 32 36 | 2e 69 78 2e 6e 65 74 63 |-ca10-26|.ix.netc|
|00000160| 6f 6d 2e 63 6f 6d 0a 4d | 69 6d 65 2d 56 65 72 73 |om.com.M|ime-Vers|
|00000170| 69 6f 6e 3a 20 31 2e 30 | 0a 43 6f 6e 74 65 6e 74 |ion: 1.0|.Content|
|00000180| 2d 54 79 70 65 3a 20 74 | 65 78 74 2f 70 6c 61 69 |-Type: t|ext/plai|
|00000190| 6e 3b 20 63 68 61 72 73 | 65 74 3d 75 73 2d 61 73 |n; chars|et=us-as|
|000001a0| 63 69 69 0a 43 6f 6e 74 | 65 6e 74 2d 54 72 61 6e |cii.Cont|ent-Tran|
|000001b0| 73 66 65 72 2d 45 6e 63 | 6f 64 69 6e 67 3a 20 37 |sfer-Enc|oding: 7|
|000001c0| 62 69 74 0a 58 2d 4e 45 | 54 43 4f 4d 2d 44 61 74 |bit.X-NE|TCOM-Dat|
|000001d0| 65 3a 20 54 68 75 20 46 | 65 62 20 30 38 20 20 37 |e: Thu F|eb 08 7|
|000001e0| 3a 31 33 3a 32 39 20 41 | 4d 20 50 53 54 20 31 39 |:13:29 A|M PST 19|
|000001f0| 39 36 0a 58 2d 4d 61 69 | 6c 65 72 3a 20 4d 6f 7a |96.X-Mai|ler: Moz|
|00000200| 69 6c 6c 61 20 32 2e 30 | 62 36 62 20 28 57 69 6e |illa 2.0|b6b (Win|
|00000210| 31 36 3b 20 49 29 0a 54 | 6f 3a 20 79 62 61 79 40 |16; I).T|o: ybay@|
|00000220| 64 69 67 65 78 2e 6e 65 | 74 0a 0a 79 62 61 79 40 |digex.ne|t..ybay@|
|00000230| 64 69 67 65 78 2e 6e 65 | 74 20 77 72 6f 74 65 3a |digex.ne|t wrote:|
|00000240| 0a 3e 20 0a 3e 20 43 61 | 6e 20 73 6f 6d 65 62 6f |.> .> Ca|n somebo|
|00000250| 64 79 20 63 6f 75 6c 64 | 20 70 6c 65 61 73 65 20 |dy could| please |
|00000260| 68 65 6c 70 20 6d 65 20 | 63 6f 6e 76 65 72 74 20 |help me |convert |
|00000270| 72 65 67 75 6c 61 72 20 | 6d 6d 2f 64 64 2f 79 79 |regular |mm/dd/yy|
|00000280| 20 66 6f 72 6d 61 74 73 | 20 74 6f 0a 3e 20 6a 75 | formats| to.> ju|
|00000290| 6c 69 61 6e 20 64 61 74 | 65 20 66 6f 72 6d 61 74 |lian dat|e format|
|000002a0| 2e 20 49 20 77 6f 75 6c | 64 20 61 70 70 72 65 63 |. I woul|d apprec|
|000002b0| 69 61 74 65 20 69 74 2e | 20 54 68 61 6e 6b 73 0a |iate it.| Thanks.|
|000002c0| 0a 2f 2a 20 54 68 69 73 | 20 66 75 6e 63 74 69 6f |./* This| functio|
|000002d0| 6e 20 63 6f 6e 76 65 72 | 74 73 20 61 20 63 6f 6e |n conver|ts a con|
|000002e0| 76 65 6e 74 69 6f 6e 61 | 6c 20 64 61 74 65 20 73 |ventiona|l date s|
|000002f0| 74 6f 72 65 64 20 69 6e | 20 61 20 73 74 72 69 6e |tored in| a strin|
|00000300| 67 20 61 73 20 4d 4d 2f | 44 44 2f 59 59 0a 20 20 |g as MM/|DD/YY. |
|00000310| 20 74 6f 20 61 20 4a 75 | 6c 69 61 6e 20 64 61 74 | to a Ju|lian dat|
|00000320| 65 20 74 6f 20 62 65 20 | 73 74 6f 72 65 64 20 69 |e to be |stored i|
|00000330| 6e 20 61 20 73 74 72 69 | 6e 67 20 61 73 20 79 79 |n a stri|ng as yy|
|00000340| 64 64 64 2e 0a 20 20 20 | 53 79 6e 74 61 78 3a 20 |ddd.. |Syntax: |
|00000350| 69 6e 74 20 43 76 74 54 | 6f 4a 75 6c 69 61 6e 28 |int CvtT|oJulian(|
|00000360| 63 68 61 72 20 2a 70 73 | 74 72 4a 75 6c 69 61 6e |char *ps|trJulian|
|00000370| 2c 20 63 68 61 72 20 2a | 70 73 74 72 44 61 74 65 |, char *|pstrDate|
|00000380| 29 0a 20 20 20 52 65 74 | 75 72 6e 20 76 61 6c 75 |). Ret|urn valu|
|00000390| 65 3a 20 2d 31 20 69 66 | 20 61 6e 20 69 6e 76 61 |e: -1 if| an inva|
|000003a0| 6c 69 64 20 64 61 74 65 | 20 69 73 20 73 75 70 70 |lid date| is supp|
|000003b0| 6c 69 65 64 0a 09 09 20 | 30 20 69 66 20 74 68 65 |lied... |0 if the|
|000003c0| 20 64 61 74 65 20 69 73 | 20 73 75 63 63 65 73 73 | date is| success|
|000003d0| 66 75 6c 6c 79 20 63 6f | 6e 76 65 72 74 65 64 0a |fully co|nverted.|
|000003e0| 2a 2f 0a 0a 23 69 6e 63 | 6c 75 64 65 20 3c 73 74 |*/..#inc|lude <st|
|000003f0| 72 69 6e 67 2e 68 3e 0a | 23 69 6e 63 6c 75 64 65 |ring.h>.|#include|
|00000400| 20 3c 73 74 64 69 6f 2e | 68 3e 0a 23 69 6e 63 6c | <stdio.|h>.#incl|
|00000410| 75 64 65 20 3c 73 74 64 | 6c 69 62 2e 68 3e 0a 0a |ude <std|lib.h>..|
|00000420| 69 6e 74 20 43 76 74 54 | 6f 4a 75 6c 69 61 6e 28 |int CvtT|oJulian(|
|00000430| 63 68 61 72 20 2a 70 73 | 74 72 4a 75 6c 69 61 6e |char *ps|trJulian|
|00000440| 2c 20 63 68 61 72 20 2a | 70 73 74 72 44 61 74 65 |, char *|pstrDate|
|00000450| 29 0a 7b 20 20 69 6e 74 | 20 6d 6d 2c 20 64 64 2c |).{ int| mm, dd,|
|00000460| 20 79 79 2c 20 59 59 2c | 20 64 64 64 3b 0a 20 20 | yy, YY,| ddd;. |
|00000470| 20 69 6e 74 20 62 4c 65 | 61 70 59 65 61 72 3b 0a | int bLe|apYear;.|
|00000480| 20 20 20 73 74 61 74 69 | 63 20 6e 44 61 79 73 5b | stati|c nDays[|
|00000490| 31 33 5d 20 3d 20 7b 30 | 2c 20 2f 2a 20 6e 6f 20 |13] = {0|, /* no |
|000004a0| 64 61 79 73 20 70 72 65 | 63 65 65 64 20 4a 61 6e |days pre|ceed Jan|
|000004b0| 75 61 72 79 20 2a 2f 0a | 09 09 20 20 20 20 20 20 |uary */.|.. |
|000004c0| 20 33 31 2c 20 2f 2a 20 | 4a 61 6e 75 61 72 79 20 | 31, /* |January |
|000004d0| 77 61 73 20 33 31 20 64 | 61 79 73 20 2a 2f 0a 09 |was 31 d|ays */..|
|000004e0| 09 20 20 20 20 20 20 20 | 35 39 2c 20 2f 2a 20 61 |. |59, /* a|
|000004f0| 64 64 20 32 38 20 6d 6f | 72 65 20 28 75 73 75 61 |dd 28 mo|re (usua|
|00000500| 6c 6c 79 29 20 66 6f 72 | 20 46 65 62 72 75 61 72 |lly) for| Februar|
|00000510| 79 20 2a 2f 0a 09 09 20 | 20 20 20 20 20 20 39 30 |y */... | 90|
|00000520| 2c 20 2f 2a 20 61 6e 64 | 20 61 6e 6f 74 68 65 72 |, /* and| another|
|00000530| 20 33 31 20 66 6f 72 20 | 4d 61 72 63 68 20 2a 2f | 31 for |March */|
|00000540| 0a 09 09 20 20 20 20 20 | 20 20 31 32 30 2c 20 2f |... | 120, /|
|00000550| 2a 20 61 6e 64 20 61 6e | 6f 74 68 65 72 20 33 30 |* and an|other 30|
|00000560| 20 66 6f 72 20 41 70 72 | 69 6c 20 2a 2f 0a 09 09 | for Apr|il */...|
|00000570| 20 20 20 20 20 20 20 31 | 35 31 2c 20 2f 2a 20 61 | 1|51, /* a|
|00000580| 6e 64 20 61 6e 6f 74 68 | 65 72 20 33 31 20 66 6f |nd anoth|er 31 fo|
|00000590| 72 20 4d 61 79 20 2a 2f | 0a 09 09 20 20 20 20 20 |r May */|... |
|000005a0| 20 20 31 38 31 2c 20 2f | 2a 20 61 6e 64 20 61 6e | 181, /|* and an|
|000005b0| 6f 74 68 65 72 20 33 30 | 20 66 6f 72 20 4a 75 6e |other 30| for Jun|
|000005c0| 65 20 2a 2f 0a 09 09 20 | 20 20 20 20 20 20 32 31 |e */... | 21|
|000005d0| 32 2c 20 2f 2a 20 61 6e | 64 20 61 6e 6f 74 68 65 |2, /* an|d anothe|
|000005e0| 72 20 33 31 20 66 6f 72 | 20 4a 75 6c 79 20 2a 2f |r 31 for| July */|
|000005f0| 0a 09 09 20 20 20 20 20 | 20 20 32 34 33 2c 20 2f |... | 243, /|
|00000600| 2a 20 61 6e 64 20 61 6e | 6f 74 68 65 72 20 33 31 |* and an|other 31|
|00000610| 20 66 6f 72 20 41 75 67 | 75 73 74 20 2a 2f 0a 09 | for Aug|ust */..|
|00000620| 09 20 20 20 20 20 20 20 | 32 37 33 2c 20 2f 2a 20 |. |273, /* |
|00000630| 61 6e 64 20 61 6e 6f 74 | 68 65 72 20 33 30 20 66 |and anot|her 30 f|
|00000640| 6f 72 20 53 65 70 74 65 | 6d 62 65 72 20 2a 2f 0a |or Septe|mber */.|
|00000650| 09 09 20 20 20 20 20 20 | 20 33 30 34 2c 20 2f 2a |.. | 304, /*|
|00000660| 20 61 6e 64 20 61 6e 6f | 74 68 65 72 20 33 31 20 | and ano|ther 31 |
|00000670| 66 6f 72 20 4f 63 74 6f | 62 65 72 20 2a 2f 0a 09 |for Octo|ber */..|
|00000680| 09 20 20 20 20 20 20 20 | 33 33 34 2c 20 2f 2a 20 |. |334, /* |
|00000690| 61 6e 64 20 61 6e 6f 74 | 68 65 72 20 33 30 20 66 |and anot|her 30 f|
|000006a0| 6f 72 20 4e 6f 76 65 6d | 62 65 72 20 2a 2f 0a 09 |or Novem|ber */..|
|000006b0| 09 20 20 20 20 20 20 20 | 33 36 35 20 2f 2a 20 61 |. |365 /* a|
|000006c0| 6e 64 20 61 6e 6f 74 68 | 65 72 20 33 31 20 66 6f |nd anoth|er 31 fo|
|000006d0| 72 20 44 65 63 65 6d 62 | 65 72 20 67 69 76 65 73 |r Decemb|er gives|
|000006e0| 20 33 36 35 20 64 61 79 | 73 20 2a 2f 0a 09 09 20 | 365 day|s */... |
|000006f0| 20 20 20 20 20 7d 3b 0a | 20 20 20 6d 6d 20 3d 20 | };.| mm = |
|00000700| 61 74 6f 69 28 73 74 72 | 74 6f 6b 28 70 73 74 72 |atoi(str|tok(pstr|
|00000710| 44 61 74 65 2c 20 22 2f | 22 29 29 3b 20 2f 2a 20 |Date, "/|")); /* |
|00000720| 65 78 74 72 61 63 74 20 | 74 68 65 20 4d 4d 20 66 |extract |the MM f|
|00000730| 69 65 6c 64 20 2a 2f 0a | 20 20 20 64 64 20 3d 20 |ield */.| dd = |
|00000740| 61 74 6f 69 28 73 74 72 | 74 6f 6b 28 4e 55 4c 4c |atoi(str|tok(NULL|
|00000750| 2c 20 22 2f 22 29 29 3b | 20 2f 2a 20 61 6e 64 20 |, "/"));| /* and |
|00000760| 74 68 65 20 44 44 20 66 | 69 65 6c 64 20 2a 2f 0a |the DD f|ield */.|
|00000770| 20 20 20 79 79 20 3d 20 | 61 74 6f 69 28 73 74 72 | yy = |atoi(str|
|00000780| 74 6f 6b 28 4e 55 4c 4c | 2c 20 22 5c 6e 22 29 29 |tok(NULL|, "\n"))|
|00000790| 3b 20 2f 2a 20 61 6e 64 | 20 74 68 65 20 59 59 20 |; /* and| the YY |
|000007a0| 66 69 65 6c 64 20 2a 2f | 0a 0a 20 20 20 2f 2a 20 |field */|.. /* |
|000007b0| 61 20 70 72 65 6c 69 6d | 69 6e 61 72 79 20 73 61 |a prelim|inary sa|
|000007c0| 6e 69 74 79 20 63 68 65 | 63 6b 2e 2e 2e 20 2a 2f |nity che|ck... */|
|000007d0| 0a 20 20 20 69 66 20 28 | 6d 6d 3c 31 20 7c 7c 20 |. if (|mm<1 || |
|000007e0| 6d 6d 3e 31 32 20 7c 7c | 20 64 64 3c 31 29 20 72 |mm>12 ||| dd<1) r|
|000007f0| 65 74 75 72 6e 20 2d 31 | 3b 0a 0a 20 20 20 2f 2a |eturn -1|;.. /*|
|00000800| 20 74 68 65 20 64 64 64 | 20 70 61 72 74 20 6f 66 | the ddd| part of|
|00000810| 20 74 68 65 20 72 65 73 | 75 6c 74 20 69 73 20 74 | the res|ult is t|
|00000820| 68 65 20 6f 72 64 69 6e | 61 6c 20 64 61 79 20 6e |he ordin|al day n|
|00000830| 75 6d 62 65 72 20 77 69 | 74 68 69 6e 20 74 68 65 |umber wi|thin the|
|00000840| 20 79 65 61 72 3b 0a 20 | 20 20 20 20 20 74 68 65 | year;. | the|
|00000850| 20 64 61 79 20 6f 66 20 | 74 68 65 20 6d 6f 6e 74 | day of |the mont|
|00000860| 68 20 70 6c 75 73 20 74 | 68 65 20 6e 75 6d 62 65 |h plus t|he numbe|
|00000870| 72 20 6f 66 20 64 61 79 | 20 69 6e 20 61 6c 6c 20 |r of day| in all |
|00000880| 74 68 65 20 70 72 65 63 | 65 65 64 69 6e 67 0a 20 |the prec|eeding. |
|00000890| 20 20 20 20 20 6d 6f 6e | 74 68 73 20 2a 2f 0a 20 | mon|ths */. |
|000008a0| 20 20 64 64 64 20 3d 20 | 64 64 2b 6e 44 61 79 73 | ddd = |dd+nDays|
|000008b0| 5b 6d 6d 2d 31 5d 3b 0a | 0a 20 20 20 2f 2a 20 69 |[mm-1];.|. /* i|
|000008c0| 6e 20 6f 72 64 65 72 20 | 74 6f 20 69 6c 6c 75 73 |n order |to illus|
|000008d0| 74 72 61 74 65 20 74 68 | 65 20 77 68 6f 6c 65 20 |trate th|e whole |
|000008e0| 70 72 6f 63 65 73 73 2c | 20 49 27 6d 20 67 6f 69 |process,| I'm goi|
|000008f0| 6e 67 20 74 6f 20 6d 61 | 6b 65 20 61 6e 0a 20 20 |ng to ma|ke an. |
|00000900| 20 20 20 20 61 73 73 75 | 6d 70 74 69 6f 6e 20 61 | assu|mption a|
|00000910| 62 6f 75 74 20 74 68 65 | 20 63 65 6e 74 75 72 79 |bout the| century|
|00000920| 20 70 61 72 74 20 6f 66 | 20 74 68 65 20 64 61 74 | part of| the dat|
|00000930| 65 3b 20 79 6f 75 20 6d | 61 79 20 77 61 6e 74 20 |e; you m|ay want |
|00000940| 74 6f 20 63 68 61 6e 67 | 65 0a 20 20 20 20 20 20 |to chang|e. |
|00000950| 74 68 69 73 20 69 66 20 | 79 6f 75 20 6b 6e 6f 77 |this if |you know|
|00000960| 20 73 6f 6d 65 74 68 69 | 6e 67 20 61 62 6f 75 74 | somethi|ng about|
|00000970| 20 74 68 65 20 72 61 6e | 67 65 20 6f 66 20 79 65 | the ran|ge of ye|
|00000980| 61 72 73 20 63 6f 76 65 | 72 65 64 20 62 79 20 79 |ars cove|red by y|
|00000990| 6f 75 72 0a 20 20 20 20 | 20 20 64 61 74 61 2c 20 |our. | data, |
|000009a0| 6f 72 20 69 66 20 79 6f | 75 20 63 61 6e 20 63 68 |or if yo|u can ch|
|000009b0| 61 6e 67 65 20 74 68 65 | 20 69 6e 70 75 74 20 66 |ange the| input f|
|000009c0| 6f 72 6d 61 74 20 74 6f | 20 69 6e 63 6c 75 64 65 |ormat to| include|
|000009d0| 20 74 68 65 20 63 65 6e | 74 75 72 79 3b 0a 20 20 | the cen|tury;. |
|000009e0| 20 20 20 20 69 2e 65 2e | 20 4d 4d 2f 44 44 2f 59 | i.e.| MM/DD/Y|
|000009f0| 59 59 59 0a 20 20 20 2a | 2f 0a 20 20 20 69 66 20 |YYY. *|/. if |
|00000a00| 28 79 79 3e 3d 38 30 29 | 20 59 59 20 3d 20 79 79 |(yy>=80)| YY = yy|
|00000a10| 2b 31 39 30 30 3b 0a 20 | 20 20 65 6c 73 65 20 59 |+1900;. | else Y|
|00000a20| 59 20 3d 20 79 79 2b 32 | 30 30 30 3b 0a 0a 20 20 |Y = yy+2|000;.. |
|00000a30| 20 2f 2a 20 6e 6f 77 20 | 6c 65 74 27 73 20 66 69 | /* now |let's fi|
|00000a40| 67 75 72 65 20 6f 75 74 | 20 69 66 20 74 68 69 73 |gure out| if this|
|00000a50| 20 69 73 20 61 20 6c 65 | 61 70 20 79 65 61 72 3b | is a le|ap year;|
|00000a60| 20 62 65 63 61 75 73 65 | 20 61 20 79 65 61 72 20 | because| a year |
|00000a70| 68 61 73 20 33 36 35 2e | 32 34 31 0a 20 20 20 20 |has 365.|241. |
|00000a80| 20 20 64 61 79 73 20 28 | 6e 65 61 72 6c 79 20 31 | days (|nearly 1|
|00000a90| 2f 34 20 64 61 79 20 65 | 78 74 72 61 29 20 77 65 |/4 day e|xtra) we|
|00000aa0| 20 61 64 64 20 61 20 6c | 65 61 70 20 64 61 79 20 | add a l|eap day |
|00000ab0| 65 76 65 72 79 20 66 6f | 75 72 74 68 20 79 65 61 |every fo|urth yea|
|00000ac0| 72 20 6f 6e 0a 20 20 20 | 20 20 20 74 68 6f 73 65 |r on. | those|
|00000ad0| 20 79 65 61 72 73 20 74 | 68 61 74 20 61 72 65 20 | years t|hat are |
|00000ae0| 65 76 65 6e 6c 79 20 64 | 69 76 69 73 69 62 6c 65 |evenly d|ivisible|
|00000af0| 20 62 79 20 34 20 28 74 | 68 75 73 20 31 39 39 36 | by 4 (t|hus 1996|
|00000b00| 20 69 73 20 61 20 6c 65 | 61 70 20 79 65 61 72 29 | is a le|ap year)|
|00000b10| 0a 20 20 20 20 20 20 2a | 2f 0a 20 20 20 62 4c 65 |. *|/. bLe|
|00000b20| 61 70 59 65 61 72 20 3d | 20 59 59 25 34 3d 3d 30 |apYear =| YY%4==0|
|00000b30| 3b 0a 20 20 20 2f 2a 20 | 62 75 74 20 62 65 63 61 |;. /* |but beca|
|00000b40| 75 73 65 20 2e 32 34 31 | 20 69 73 20 6e 6f 74 20 |use .241| is not |
|00000b50| 71 75 69 74 65 20 31 2f | 34 2c 20 77 65 20 6f 6d |quite 1/|4, we om|
|00000b60| 69 74 20 6f 6e 65 20 6c | 65 61 70 20 79 65 61 72 |it one l|eap year|
|00000b70| 20 65 76 65 72 79 20 31 | 30 30 0a 20 20 20 20 20 | every 1|00. |
|00000b80| 20 79 65 61 72 73 20 6f | 6e 20 74 68 6f 73 65 20 | years o|n those |
|00000b90| 79 65 61 72 73 20 74 68 | 61 74 20 61 72 65 20 65 |years th|at are e|
|00000ba0| 76 65 6e 6c 79 20 64 69 | 76 69 73 69 62 6c 65 20 |venly di|visible |
|00000bb0| 62 79 20 31 30 30 20 28 | 31 39 30 30 20 77 61 73 |by 100 (|1900 was|
|00000bc0| 20 6e 6f 74 20 61 0a 20 | 20 20 20 20 20 6c 65 61 | not a. | lea|
|00000bd0| 70 20 79 65 61 72 20 2a | 2f 0a 20 20 20 69 66 20 |p year *|/. if |
|00000be0| 28 59 59 25 31 30 30 3d | 3d 30 29 20 62 4c 65 61 |(YY%100=|=0) bLea|
|00000bf0| 70 59 65 61 72 20 3d 20 | 30 3b 0a 20 20 20 2f 2a |pYear = |0;. /*|
|00000c00| 20 62 75 74 20 6e 6f 77 | 20 77 65 20 6e 65 65 64 | but now| we need|
|00000c10| 20 74 6f 20 61 64 64 20 | 62 61 63 6b 20 6f 6e 65 | to add |back one|
|00000c20| 20 6c 65 61 70 20 79 65 | 61 72 20 65 76 65 72 79 | leap ye|ar every|
|00000c30| 20 31 30 30 30 20 79 65 | 61 72 73 20 6f 6e 20 74 | 1000 ye|ars on t|
|00000c40| 68 6f 73 65 0a 20 20 20 | 20 20 20 79 65 61 72 73 |hose. | years|
|00000c50| 20 74 68 61 74 20 61 72 | 65 20 65 76 65 6e 6c 79 | that ar|e evenly|
|00000c60| 20 64 69 76 69 73 69 62 | 6c 65 20 62 79 20 31 30 | divisib|le by 10|
|00000c70| 30 30 20 28 74 68 65 20 | 79 65 61 72 20 32 30 30 |00 (the |year 200|
|00000c80| 30 2c 20 69 6e 20 61 64 | 64 69 74 69 6f 6e 20 74 |0, in ad|dition t|
|00000c90| 6f 0a 20 20 20 20 20 20 | 74 68 65 20 6f 74 68 65 |o. |the othe|
|00000ca0| 72 20 70 72 6f 62 6c 65 | 6d 73 20 74 68 61 74 20 |r proble|ms that |
|00000cb0| 69 74 20 6d 61 79 20 63 | 61 75 73 65 20 69 6e 20 |it may c|ause in |
|00000cc0| 64 61 74 65 20 70 72 6f | 63 65 73 73 69 6e 67 2c |date pro|cessing,|
|00000cd0| 20 69 73 20 74 68 65 20 | 66 69 72 73 74 0a 20 20 | is the |first. |
|00000ce0| 20 20 20 20 74 69 6d 65 | 2c 20 65 76 65 72 2c 20 | time|, ever, |
|00000cf0| 74 68 61 74 20 74 68 69 | 73 20 69 73 20 64 6f 6e |that thi|s is don|
|00000d00| 65 3b 20 74 68 65 79 20 | 64 69 64 6e 27 74 20 77 |e; they |didn't w|
|00000d10| 6f 72 72 79 20 61 62 6f | 75 74 20 6c 65 61 70 20 |orry abo|ut leap |
|00000d20| 79 65 61 72 20 62 61 63 | 6b 0a 20 20 20 20 20 20 |year bac|k. |
|00000d30| 69 6e 20 74 68 65 20 79 | 65 61 72 20 31 30 30 30 |in the y|ear 1000|
|00000d40| 29 20 2a 2f 0a 20 20 20 | 69 66 20 28 59 59 25 31 |) */. |if (YY%1|
|00000d50| 30 30 30 3d 3d 30 29 20 | 62 4c 65 61 70 59 65 61 |000==0) |bLeapYea|
|00000d60| 72 20 3d 20 31 3b 0a 20 | 20 20 2f 2a 20 69 66 20 |r = 1;. | /* if |
|00000d70| 79 6f 75 20 22 6b 6e 6f | 77 22 20 74 68 61 74 20 |you "kno|w" that |
|00000d80| 61 6c 6c 20 6f 66 20 79 | 6f 75 72 20 64 61 74 65 |all of y|our date|
|00000d90| 73 20 66 61 6c 6c 20 77 | 69 74 68 69 6e 20 74 68 |s fall w|ithin th|
|00000da0| 65 20 72 61 6e 67 65 20 | 66 72 6f 6d 20 31 39 38 |e range |from 198|
|00000db0| 30 0a 20 20 20 20 20 20 | 74 6f 20 32 30 37 39 20 |0. |to 2079 |
|00000dc0| 79 6f 75 20 63 61 6e 20 | 65 6c 69 6d 69 6e 61 74 |you can |eliminat|
|00000dd0| 65 20 74 68 65 20 70 72 | 65 76 69 6f 75 73 20 74 |e the pr|evious t|
|00000de0| 77 6f 20 74 65 73 74 20 | 62 65 63 61 75 73 65 20 |wo test |because |
|00000df0| 65 76 65 72 79 20 66 6f | 75 72 74 68 0a 20 20 20 |every fo|urth. |
|00000e00| 20 20 20 79 65 61 72 20 | 64 75 72 69 6e 67 20 74 | year |during t|
|00000e10| 68 69 73 20 65 6e 74 69 | 72 65 20 70 65 72 69 6f |his enti|re perio|
|00000e20| 64 20 49 53 20 61 20 6c | 65 61 70 20 79 65 61 72 |d IS a l|eap year|
|00000e30| 20 2a 2f 0a 0a 20 20 20 | 2f 2a 20 77 65 20 63 61 | */.. |/* we ca|
|00000e40| 6e 20 6e 65 77 20 63 68 | 65 63 6b 20 64 64 20 74 |n new ch|eck dd t|
|00000e50| 6f 20 6d 61 6b 65 20 73 | 75 72 65 20 69 74 20 66 |o make s|ure it f|
|00000e60| 61 6c 6c 73 20 77 69 74 | 68 69 6e 20 74 68 65 20 |alls wit|hin the |
|00000e70| 70 72 6f 70 65 72 20 72 | 61 6e 67 65 20 66 6f 72 |proper r|ange for|
|00000e80| 0a 20 20 20 20 20 20 74 | 68 65 20 6d 6f 6e 74 68 |. t|he month|
|00000e90| 20 2a 2f 0a 20 20 20 69 | 66 20 28 6d 6d 3d 3d 32 | */. i|f (mm==2|
|00000ea0| 29 20 7b 0a 20 20 20 20 | 20 20 2f 2a 20 69 66 20 |) {. | /* if |
|00000eb0| 74 68 69 73 20 69 73 20 | 46 65 62 72 75 61 72 79 |this is |February|
|00000ec0| 20 69 74 20 64 65 70 65 | 6e 64 73 20 75 70 6f 6e | it depe|nds upon|
|00000ed0| 20 77 68 65 74 68 65 72 | 20 74 68 69 73 20 69 73 | whether| this is|
|00000ee0| 20 61 20 6c 65 61 70 20 | 79 65 61 72 20 2a 2f 0a | a leap |year */.|
|00000ef0| 20 20 20 20 20 20 69 66 | 20 28 62 4c 65 61 70 59 | if| (bLeapY|
|00000f00| 65 61 72 29 20 7b 0a 09 | 20 2f 2a 20 69 66 20 69 |ear) {..| /* if i|
|00000f10| 74 73 20 61 20 6c 65 61 | 70 20 79 65 61 72 20 74 |ts a lea|p year t|
|00000f20| 68 65 20 6d 61 78 20 69 | 73 20 32 39 20 2a 2f 0a |he max i|s 29 */.|
|00000f30| 09 20 69 66 20 28 64 64 | 3e 32 39 29 20 72 65 74 |. if (dd|>29) ret|
|00000f40| 75 72 6e 20 2d 31 3b 0a | 09 09 20 20 20 20 20 7d |urn -1;.|.. }|
|00000f50| 0a 20 20 20 20 20 20 65 | 6c 73 65 20 7b 0a 09 20 |. e|lse {.. |
|00000f60| 2f 2a 20 69 66 20 69 74 | 73 20 6e 6f 74 20 61 20 |/* if it|s not a |
|00000f70| 6c 65 61 70 20 79 65 61 | 72 20 74 68 65 20 6d 61 |leap yea|r the ma|
|00000f80| 78 20 69 73 20 32 38 20 | 2a 2f 0a 09 20 69 66 20 |x is 28 |*/.. if |
|00000f90| 28 64 64 3e 32 38 29 20 | 72 65 74 75 72 6e 20 2d |(dd>28) |return -|
|00000fa0| 31 3b 0a 09 20 20 20 7d | 20 20 7d 0a 20 20 20 65 |1;.. }| }. e|
|00000fb0| 6c 73 65 20 7b 0a 20 20 | 20 20 20 20 2f 2a 20 66 |lse {. | /* f|
|00000fc0| 6f 72 20 74 68 65 20 6f | 74 68 65 72 20 6d 6f 6e |or the o|ther mon|
|00000fd0| 74 68 73 20 75 73 65 20 | 74 68 65 20 74 61 62 6c |ths use |the tabl|
|00000fe0| 65 20 6f 66 20 64 61 79 | 73 20 61 62 6f 76 65 20 |e of day|s above |
|00000ff0| 74 6f 20 66 69 67 75 72 | 65 20 6f 75 74 20 68 6f |to figur|e out ho|
|00001000| 77 0a 09 20 6c 6f 6e 67 | 20 74 68 65 20 6d 6f 6e |w.. long| the mon|
|00001010| 74 68 20 6d 61 79 20 62 | 65 20 2a 2f 0a 20 20 20 |th may b|e */. |
|00001020| 20 20 20 69 66 20 28 64 | 64 3e 28 6e 44 61 79 73 | if (d|d>(nDays|
|00001030| 5b 6d 6d 5d 2d 6e 44 61 | 79 73 5b 6d 6d 2d 31 5d |[mm]-nDa|ys[mm-1]|
|00001040| 29 29 20 72 65 74 75 72 | 6e 20 2d 31 3b 0a 09 7d |)) retur|n -1;..}|
|00001050| 0a 0a 20 20 20 2f 2a 20 | 69 66 20 74 68 69 73 20 |.. /* |if this |
|00001060| 69 73 20 61 20 6c 65 61 | 70 20 79 65 61 72 20 2a |is a lea|p year *|
|00001070| 2f 0a 20 20 20 69 66 20 | 28 62 4c 65 61 70 59 65 |/. if |(bLeapYe|
|00001080| 61 72 29 0a 20 20 20 20 | 20 20 2f 2a 20 61 6e 64 |ar). | /* and|
|00001090| 20 69 74 73 20 6f 6e 65 | 20 6f 66 20 74 68 65 20 | its one| of the |
|000010a0| 6d 6f 6e 74 68 73 20 61 | 66 74 65 72 20 46 65 62 |months a|fter Feb|
|000010b0| 72 75 61 72 79 2c 20 61 | 64 64 20 74 68 65 20 65 |ruary, a|dd the e|
|000010c0| 78 74 72 61 20 64 61 79 | 20 2a 2f 0a 20 20 20 20 |xtra day| */. |
|000010d0| 20 20 69 66 20 28 6d 6d | 3e 3d 33 29 20 64 64 64 | if (mm|>=3) ddd|
|000010e0| 2b 2b 3b 0a 0a 20 20 20 | 2f 2a 20 6e 6f 77 2c 20 |++;.. |/* now, |
|000010f0| 70 61 63 6b 20 74 68 65 | 20 79 65 61 72 20 61 6e |pack the| year an|
|00001100| 64 20 64 61 79 20 62 61 | 63 6b 20 74 6f 67 65 74 |d day ba|ck toget|
|00001110| 68 65 72 20 74 68 65 20 | 77 61 79 20 74 68 65 79 |her the |way they|
|00001120| 20 6c 69 6b 65 20 74 6f | 20 73 65 65 20 74 68 65 | like to| see the|
|00001130| 0a 20 20 20 20 20 20 72 | 65 73 75 6c 74 20 2a 2f |. r|esult */|
|00001140| 0a 20 20 20 73 70 72 69 | 6e 74 66 28 70 73 74 72 |. spri|ntf(pstr|
|00001150| 4a 75 6c 69 61 6e 2c 20 | 22 25 30 32 64 25 30 33 |Julian, |"%02d%03|
|00001160| 64 22 2c 20 79 79 2c 20 | 64 64 64 29 3b 0a 0a 20 |d", yy, |ddd);.. |
|00001170| 20 20 72 65 74 75 72 6e | 20 30 3b 0a 7d 0a | return| 0;.}. |
+--------+-------------------------+-------------------------+--------+--------+